<template>
  <a-card :bordered="false">
    <div style="padding: 14px 0">
      <div style="display: flex">
        <div style="width: 140px; line-height: 32px; font-weight: bold; color: #000">{{ $t('会员守则') }}</div>
        <a-row :gutter="[0, 24]" style="width: calc(100% - 140px)">
          <a-col :span="24">
            <a-checkbox style="line-height: 32px" v-model="info.states">
              {{ $t('启用') }}
            </a-checkbox>
            <span style="margin-left: 15px; color: orange">{{ $t('（启用后APP注册时需先阅读会员守则，否则禁止注册）') }}</span>
          </a-col>
        </a-row>
      </div>
      <div style="display: flex; margin-top: 20px;">
        <div style="width: 140px; line-height: 32px; font-weight: bold; color: #000"> {{ $t('守则内容') }}</div>
        <a-row :gutter="[0, 24]" style="width: calc(100% - 140px)">
          <a-col :span="24">
            <j-editor v-model="info.content" />
          </a-col>
        </a-row>
      </div>
    </div>
    <div style="margin: 10px">
      <a-button @click="saveInfo" style="background-color: #f96455; border-color: #f96455; color: #ffffff" v-has="'memberRegulations:edit'">
        {{ $t('保存') }}</a-button>
    </div>
  </a-card>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'BisMemberRegulationsList',
  data() {
    return {
      description: '会员守则',
      info: {
        states: false,
      },
    }
  },
  created() {
    this.getList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    modalFormOk() {
      this.loadData(1)
    },
    saveInfo() {
      let url = '', method = '', querydata = {}
      if (this.info.id) {
        url = '/applet/bisMemberRegulations/edit'
        method = 'put'
      } else {
        url = '/applet/bisMemberRegulations/add'
        method = 'post'
      }
      querydata = Object.assign({}, this.info, {
        status: this.info.states ? 1 : 0,
        content: this.info.content
      })
      httpAction(url, querydata, method).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      })
    },
    initDictConfig() { },
    getList() {
      getAction('/applet/bisMemberRegulations/list', {}).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            this.info = res.result.records[0]
            this.$set(this.info, 'states', this.info.status ? true : false)
          }
        } else {
          this.$message.warning(res.message)
        }
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
<style>
.table-padlr0 .ant-table.ant-table-small>.ant-table-content>.ant-table-body {
  margin: 0;
}

.table-padlr0 .ant-table-small>.ant-table-content>.ant-table-body>table>.ant-table-thead>tr>th {
  background-color: #fafafa;
}
</style>